package org.example.day20240828;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num1 = scanner.nextInt();
        int num2 = scanner.nextInt();
        int count = 0;
        Set<Integer> left = new HashSet<>();
        left.add(0);
        for (int i=0; i<num2; i++){
            int leftNum = scanner.nextInt();
            int rightNum = scanner.nextInt();
            if(!left.contains(rightNum)){
                count++;
            }
            left.add(leftNum);
        }
        System.out.println(count);
    }
}
